************************************************************************************************************************************
* REPLICATION MATERIALS FOR "Conspiracy beliefs and perceptions of electoral integrity: Cross-national evidence from 29 countries" *
* PUBLIC OPINION QUARTERLY																										   *
*																																   *
* AUTHOR: Christian Schnaudt (corresponding author), School of Social Sciences, University of Mannheim, 68131 Mannheim, Germany.   *
* E-MAIL: schnaudt@uni-mannheim.de 																								   *
* ORCID: 0000-0002-2062-7770																									   *
*																																   *
* VERSION DATE: 2023-10-06																										   *
************************************************************************************************************************************


* 1 LOAD MERGED DATA SET INCL. ESS, V-DEM, WORLD BANK & NELDA DATA FOR ANALYSIS

version 17
set more off
clear

* IMPORTANT: ADAPT THE BELOW PATH OF THE WORKING DIRECTORY TO YOUR PERSONAL ENVIRONMENT!!!
cd "C:\Users\user\Desktop\REPLICATION FILES"
use "data_merged_clean.dta"

************************************************************************************************************************************

* 2 PREPARE INDIVIDUAL- AND CONTEXTUAL-LEVEL VARIABLES FOR ANALYSIS

* 2A INDIVIDUAL-LEVEL VARIABLES (ESS)

* Conspiracy beliefs
fre secgrdec scidecpb 
bys cname: fre secgrdec scidecpb
fre secgrdec scidecpb if cntry=="FR" | cntry=="ME"

*drop FR and ME cause no data on conspiracy beliefs
drop if cntry=="FR" | cntry=="ME"

* Conspiracy beliefs scale (FR and ME missing): reverse and normalize items to 0-1
gen secgrdecr = 5-secgrdec
tab secgrdec secgrdecr, m
gen secgrdecr_nm = secgrdecr/4
fre secgrdecr_nm

gen scidecpbr = 5-scidecpb
tab scidecpb scidecpbr, m
gen scidecpbr_nm = scidecpbr/4
fre scidecpbr_nm

* Additive conspiracy beliefs scale normalized to 0-1
corr secgrdecr scidecpbr
bys cntry: corr secgrdecr scidecpbr
gen conspi = secgrdecr+scidecpbr
fre conspi
gen conspi_nm = conspi/8
fre conspi_nm

alpha secgrdecr scidecpbr

* Perceptions of electoral integrity (individual level)
fre fairelcc

************************************************************************************************************************************

* MODEL COVARIATES (INDIVIDUAL LEVEL)

* Distrust in politics
fre trstprt trstprl trstplt
factor trstprt trstprl trstplt
egen poltrst = rowmean(trstprt trstprl trstplt)
fre poltrst

gen distrst_nm = (10-poltrst)/10
fre distrst_nm

* Economic satisfaction
fre stfeco
gen stfeco_nm = stfeco/10
fre stfeco_nm

* Political interest
fre polintr
gen polint = 5-polintr
gen polintr_nm = (4-polintr)/3
fre polintr_nm

* Internal efficacy
fre actrolga cptppola
corr actrolga cptppola
gen inteff_nm = ((actrolga-1) + (cptppola-1))/8
fre inteff_nm

* L-R placement
fre lrscale
gen lrscale_nm = lrscale/10
fre lrscale_nm

* Party ID
fre clsprty
recode clsprty (1=1) (2=0), gen(pid)
fre pid

* Media use
fre nwspol
gen meduse_nm = nwspol/1440
fre meduse_nm

* Education in years
fre eduyrs
gen eduyrs_nm = eduyrs/76
fre eduyrs_nm

* Sex
fre gndr
gen female = gndr-1
fre female

* Age
fre agea
gen age_nm = (agea-15)/75
fre age_nm

* Survey mode
fre mode

* Electoral winner/loser
gen winner=.

*AT
fre prtvtcat
replace winner = 1 if (essround==10 & cntry=="AT" & prtvtcat==2) | (essround==10 & cntry=="AT" & prtvtcat==5)
replace winner = 0 if essround==10 & cntry=="AT" & prtvtcat!=2 & prtvtcat!=5 & prtvtcat!=. & prtvtcat!=.a & prtvtcat!=.d  

*BE
fre prtvtebe
replace winner = 1 if (essround==10 & cntry=="BE" & prtvtebe==7) | (essround==10 & cntry=="BE" & prtvtebe==10) | (essround==10 & cntry=="BE" & prtvtebe==11) | (essround==10 & cntry=="BE" & prtvtebe==4) | (essround==10 & cntry=="BE" & prtvtebe==2) | (essround==10 & cntry=="BE" & prtvtebe==9) | (essround==10 & cntry=="BE" & prtvtebe==1) 
replace winner = 0 if essround==10 & cntry=="BE" & prtvtebe!=7 & prtvtebe!=10 & prtvtebe!=11 & prtvtebe!=4 & prtvtebe!=2 & prtvtebe!=9 & prtvtebe!=1 & prtvtebe!=. & prtvtebe!=.a & prtvtebe!=.b & prtvtebe!=.c

*BG only interim government so using previous gov
fre prtvtebg 
replace winner = 1 if (essround==10 & cntry=="BG" & prtvtebg==1) | (essround==10 & cntry=="BG" & prtvtebg==7) | (essround==10 & cntry=="BG" & prtvtebg==8)
replace winner = 0 if essround==10 & cntry=="BG" & prtvtebg!=1 & prtvtebg!=7 & prtvtebg!=8 & prtvtebg!=. & prtvtebg!=.a & prtvtebg!=.b & prtvtebg!=.c

*CH
fre prtvthch
replace winner = 1 if (essround==10 & cntry=="CH" & prtvthch==1) | (essround==10 & cntry=="CH" & prtvthch==2) | (essround==10 & cntry=="CH" & prtvthch==3) | (essround==10 & cntry=="CH" & prtvthch==5)
replace winner = 0 if essround==10 & cntry=="CH" & prtvthch!=1 & prtvthch!=2 & prtvthch!=3 & prtvthch!=5 & prtvthch!=. & prtvthch!=.a & prtvthch!=.b & prtvthch!=.c

*CY
fre prtvtccy
replace winner = 1 if (essround==10 & cntry=="CY" & prtvtccy==8)
replace winner = 0 if essround==10 & cntry=="CY" & prtvtccy!=8 & prtvtccy!=. & prtvtccy!=.a & prtvtccy!=.d

*CZ
fre prtvtecz
replace winner = 1 if (essround==10 & cntry=="CZ" & prtvtecz==3) | (essround==10 & cntry=="CZ" & prtvtecz==5) | (essround==10 & cntry=="CZ" & prtvtecz==6) | (essround==10 & cntry=="CZ" & prtvtecz==7) | (essround==10 & cntry=="CZ" & prtvtecz==9)
replace winner = 0 if essround==10 & cntry=="CZ" & prtvtecz!=3 & prtvtecz!=5 & prtvtecz!=6 & prtvtecz!=7 & prtvtecz!=9 & prtvtecz!=. & prtvtecz!=.a & prtvtecz!=.b & prtvtecz!=.c & prtvtecz!=.d


*DE
fre prtvfde2
replace winner = 1 if (essround==10 & cntry=="DE" & prtvfde2==2)  | (essround==10 & cntry=="DE" & prtvfde2==4) | (essround==10 & cntry=="DE" & prtvfde2==5)
replace winner = 0 if essround==10 & cntry=="DE" & prtvfde2!=2 & prtvfde2!=4 & prtvfde2!=5 & prtvfde2!=. & prtvfde2!=.a & prtvfde2!=.d

*EE
fre prtvthee
replace winner = 1 if (essround==10 & cntry=="EE" & prtvthee==1) |(essround==10 & cntry=="EE" & prtvthee==2)
replace winner = 0 if essround==10 & cntry=="EE" & prtvthee!=1 & prtvthee!=2 & prtvthee!=. & prtvthee!=.a & prtvthee!=.b & prtvthee!=.c

*ES
fre prtvtfes
replace winner = 1 if (essround==10 & cntry=="ES" & prtvtfes==1) | (essround==10 & cntry=="ES" & prtvtfes==4) | (essround==10 & cntry=="ES" & prtvtfes==5)
replace winner = 0 if essround==10 & cntry=="ES" & prtvtfes!=1 & prtvtfes!=4 & prtvtfes!=5 & prtvtfes!=. & prtvtfes!=.a & prtvtfes!=.d

*FI
fre prtvtefi
replace winner = 1 if (essround==10 & cntry=="FI" & prtvtefi==2) | (essround==10 & cntry=="FI" & prtvtefi==3) | (essround==10 & cntry=="FI" & prtvtefi==16) | (essround==10 & cntry=="FI" & prtvtefi==17) | (essround==10 & cntry=="FI" & prtvtefi==18)
replace winner = 0 if essround==10 & cntry=="FI" & prtvtefi!=2 & prtvtefi!=3 & prtvtefi!=16 & prtvtefi!=17 & prtvtefi!=18 & prtvtefi!=. & prtvtefi!=.a & prtvtefi!=.b & prtvtefi!=.c

*GB
fre prtvtdgb
replace winner = 1 if (essround==10 & cntry=="GB" & prtvtdgb==1 )
replace winner = 0 if essround==10 & cntry=="GB" & prtvtdgb!=1 & prtvtdgb!=. & prtvtdgb!=.a & prtvtdgb!=.b & prtvtdgb!=.c 

*GR
fre prtvtdgr
replace winner = 1 if (essround==10 & cntry=="GR" & prtvtdgr==1)
replace winner = 0 if essround==10 & cntry=="GR" & prtvtdgr!=1 & prtvtdgr!=. & prtvtdgr!=.a & prtvtdgr!=.b & prtvtdgr!=.c 

*HR
fre prtvtbhr
replace winner = 1 if (essround==10 & cntry=="HR" & prtvtbhr==1) | (essround==10 & cntry=="HR" & prtvtbhr==9)
replace winner = 0 if essround==10 & cntry=="HR" & prtvtbhr!=1 & prtvtbhr!=9 & prtvtbhr!=. & prtvtbhr!=.a & prtvtbhr!=.b & prtvtbhr!=.c

*HU
fre prtvtghu
replace winner = 1 if (essround==10 & cntry=="HU" & prtvtghu==3) | (essround==10 & cntry=="HU" & prtvtghu==5)
replace winner = 0 if essround==10 & cntry=="HU" & prtvtghu!=3 & prtvtghu!=5 & prtvtghu!=. & prtvtghu!=.a & prtvtghu!=.b & prtvtghu!=.c

*IE
fre prtvtdie
replace winner = 1 if (essround==10 & cntry=="IE" & prtvtdie==1) | (essround==10 & cntry=="IE" & prtvtdie==2) | (essround==10 & cntry=="IE" & prtvtdie==6)
replace winner = 0 if essround==10 & cntry=="IE" & prtvtdie!=1 & prtvtdie!=2 & prtvtdie!=6 & prtvtdie!=. & prtvtdie!=.a & prtvtdie!=.b & prtvtdie!=.c

*IL
fre prtvtdil
replace winner = 1 if (essround==10 & cntry=="IL" & prtvtdil==2) | (essround==10 & cntry=="IL" & prtvtdil==3) | (essround==10 & cntry=="IL" & prtvtdil==4) | (essround==10 & cntry=="IL" & prtvtdil==5) | (essround==10 & cntry=="IL" & prtvtdil==6) | (essround==10 & cntry=="IL" & prtvtdil==7) | (essround==10 & cntry=="IL" & prtvtdil==8) 
replace winner = 0 if essround==10 & cntry=="IL" & prtvtdil!=2 & prtvtdil!=3 & prtvtdil!=4 & prtvtdil!=5 & prtvtdil!=6 & prtvtdil!=7 & prtvtdil!=8 & prtvtdil!=. & prtvtdil!=.a & prtvtdil!=.d

*IT
fre prtvtdit
replace winner = 1 if (essround==10 & cntry=="IT" & prtvtdit==1) | (essround==10 & cntry=="IT" & prtvtdit==2)
replace winner = 0 if essround==10 & cntry=="IT" & prtvtdit!=1 & prtvtdit!=2 & prtvtdit!=. & prtvtdit!=.a & prtvtdit!=.b & prtvtdit!=.c & prtvtdit!=.d

*IS 
fre prtvtdis
replace winner = 1 if (essround==10 & cntry=="IS" & prtvtdis==5) | (essround==10 & cntry=="IS" & prtvtdis==9) | (essround==10 & cntry=="IS" & prtvtdis==11)
replace winner = 0 if essround==10 & cntry=="IS" & prtvtdis!=5 & prtvtdis!=9 & prtvtdis!=11 & prtvtdis!=. & prtvtdis!=.a & prtvtdis!=.b & prtvtdis!=.c & prtvtdis!=.d

*LT 
fre prtvclt1
replace winner = 1 if (essround==10 & cntry=="LT" & prtvclt1==3) | (essround==10 & cntry=="LT" & prtvclt1==5) | (essround==10 & cntry=="LT" & prtvclt1==12)
replace winner = 0 if essround==10 & cntry=="LT" & prtvclt1!=3 & prtvclt1!=5 & prtvclt1!=12 & prtvclt1!=. & prtvclt1!=.a  & prtvclt1!=.b & prtvclt1!=.c & prtvclt1!=.d

*LV
fre prtvtalv
replace winner = 1 if (essround==10 & cntry=="LV" & prtvtalv==2) | (essround==10 & cntry=="LV" & prtvtalv==4) | (essround==10 & cntry=="LV" & prtvtalv==10) | (essround==10 & cntry=="LV" & prtvtalv==13) | (essround==10 & cntry=="LV" & prtvtalv==15)
replace winner = 0 if essround==10 & cntry=="LV" & prtvtalv!=2 & prtvtalv!=4 & prtvtalv!=10 & prtvtalv!=13 & prtvtalv!=15 & prtvtalv!=. & prtvtalv!=.a  & prtvtalv!=.d

*MK
fre prtvtmk
replace winner = 1 if (essround==10 & cntry=="MK" & prtvtmk==1)
replace winner = 0 if essround==10 & cntry=="MK" & prtvtmk!=1 & prtvtmk!=. & prtvtmk!=.a & prtvtmk!=.b & prtvtmk!=.c 

*NL
fre prtvthnl
replace winner = 1 if (essround==10 & cntry=="NL" & prtvthnl==1) | (essround==10 & cntry=="NL" & prtvthnl==5) | (essround==10 & cntry=="NL" & prtvthnl==6) | (essround==10 & cntry=="NL" & prtvthnl==7)
replace winner = 0 if essround==10 & cntry=="NL" & prtvthnl!=1 & prtvthnl!=5 & prtvthnl!=6 & prtvthnl!=7 & prtvthnl!=. & prtvthnl!=.a  & prtvthnl!=.b & prtvthnl!=.c

*NO
fre prtvtbno
replace winner = 1 if (essround==10 & cntry=="NO" & prtvtbno==3) | (essround==10 & cntry=="NO" & prtvtbno==6)
replace winner = 0 if essround==10 & cntry=="NO" & prtvtbno!=3 & prtvtbno!=6  & prtvtbno!=. & prtvtbno!=.a  & prtvtbno!=.b & prtvtbno!=.c & prtvtbno!=.d

*PL
fre prtvtepl
replace winner = 1 if (essround==10 & cntry=="PL" & prtvtepl==5)
replace winner = 0 if essround==10 & cntry=="PL" & prtvtepl!=5 & prtvtepl!=. & prtvtepl!=.a & prtvtepl!=.d

*PT
fre prtvtdpt
replace winner = 1 if (essround==10 & cntry=="PT" & prtvtdpt==18) 
replace winner = 0 if essround==10 & cntry=="PT" & prtvtdpt!=18 & prtvtdpt!=. & prtvtdpt!=.a & prtvtdpt!=.b & prtvtdpt!=.c

*RS
fre prtvtars
replace winner = 1 if (essround==10 & cntry=="RS" & prtvtars==1)| (essround==10 & cntry=="RS" & prtvtars==2)
replace winner = 0 if essround==10 & cntry=="RS" & prtvtars!=1 & prtvtars!=2 & prtvtars!=. & prtvtars!=.a & prtvtars!=.d

*SE
fre prtvtdse
replace winner = 1 if (essround==10 & cntry=="SE" & prtvtdse==6)
replace winner = 0 if essround==10 & cntry=="SE" & prtvtdse!=6 & prtvtdse!=. & prtvtdse!=.a & prtvtdse!=.d

*SI
fre prtvtfsi
replace winner = 1 if (essround==10 & cntry=="SI" & prtvtfsi==4) | (essround==10 & cntry=="SI" & prtvtfsi==8) | (essround==10 & cntry=="SI" & prtvtfsi==10)
replace winner = 0 if essround==10 & cntry=="SI" & prtvtfsi!=4 & prtvtfsi!=8 & prtvtfsi!=10 & prtvtfsi!=. & prtvtfsi!=.a & prtvtfsi!=.b & prtvtfsi!=.c & prtvtfsi!=.d

*SK
fre prtvtesk
replace winner = 1 if (essround==10 & cntry=="SK" & prtvtesk==1) | (essround==10 & cntry=="SK" & prtvtesk==3) | (essround==10 & cntry=="SK" & prtvtesk==7)
replace winner = 0 if essround==10 & cntry=="SK" & prtvtesk!=1 & prtvtesk!=3 & prtvtesk!=7 & prtvtesk!=. & prtvtesk!=.a & prtvtesk!=.b & prtvtesk!=.c & prtvtesk!=.d

fre winner
bys cntry: fre winner

* Final variable incl. non-voters/ineligibles (coding: 0=loser, 1=winner, 2=non-voters, 3=voters with unknown status, 4=ineligibles)
clonevar winner2 = winner
* non-voters
replace winner2= 2 if vote==2 
*ineligibles
replace winner2= 4 if vote==3 
*voters with no winner/loser status indicated, i.e. missings on vote choice variables
replace winner2= 3 if vote==1 & winner2==.

fre winner2 

************************************************************************************************************************************

* 2B CONTEXTUAL-LEVEL VARIABLES (V-DEM, WORLD-BANK, NELDA)

* ELECTORAL INTEGRITY: VDEM EIP-SCALE and its subdimensions normalized to 0-1
fre v2xel_frefair v2elembaut v2elembcap v2elrgstry v2elvotbuy v2elirreg v2elintim v2elpeace v2elfrfair

foreach var of varlist  v2xel_frefair v2elembaut v2elembcap v2elrgstry v2elvotbuy v2elirreg v2elintim v2elpeace v2elfrfair {
    qui summ `var'
    gen `var'_nm = (`var' - r(min)) / (r(max) - r(min))
}

fre v2xel_frefair_nm v2elembaut_nm v2elembcap_nm v2elrgstry_nm v2elvotbuy_nm v2elirreg_nm v2elintim_nm v2elpeace_nm v2elfrfair_nm
rename v2xel_frefair_nm ei_index_vdem
fre v2xel_frefair ei_index_vdem

* COMPULSORY VOTING: V-DEM recoded to dummy variable (0=no, 1=yes)
fre v2elcomvot
recode v2elcomvot (2=1),gen(compvote)
fre compvote


* GDP PER CAPITA: WORLD BANK
fre gdppc

foreach var of varlist gdppc {
    qui summ `var'
    gen `var'_nm = (`var' - r(min)) / (r(max) - r(min))
}

fre gdppc_nm


* ELECTORAL INTEGRITY: NELDA INDEX (for robustness checks only)
foreach var of varlist  nelda1 nelda2 nelda3 nelda4 nelda5 nelda6 nelda7 nelda8 nelda9 nelda10 nelda11 nelda12 nelda13 nelda14 nelda15 nelda16 nelda17 nelda18 nelda19 nelda20 nelda21 nelda22 nelda23 nelda24 nelda25 nelda26 nelda27 nelda28 nelda29 nelda30 nelda31 nelda32 nelda33 nelda34 nelda35 nelda36 nelda37 nelda38 nelda39 nelda40 nelda41 nelda42 nelda43 nelda44 nelda45 nelda46 nelda47 nelda48 nelda49 nelda50 nelda51 nelda52 nelda53 nelda54 nelda55 nelda56 nelda57 nelda58 {
	encode `var', gen(`var'_num)
	}
	
fre nelda1_num-nelda58_num

* Relevant NELDA items for measuring electoral integrity 
fre nelda3_num nelda4_num nelda5_num nelda11_num nelda13_num nelda14_num nelda15_num nelda16_num nelda28_num nelda29_num nelda30_num nelda31_num nelda33_num nelda47_num nelda48_num nelda49_num

* Recode all relebant NELDA items so that higher values reflect higher levels of electoral integrity
recode nelda3_num nelda4_num nelda5_num (1=1)
recode nelda11_num nelda13_num nelda14_num nelda15_num nelda29_num nelda48_num nelda49_num (1=1) (2=0)

fre nelda3_num nelda4_num nelda5_num nelda11_num nelda13_num nelda14_num nelda15_num nelda29_num nelda48_num nelda49_num
	
recode nelda16_num (1 2=1) (3=0)

recode nelda28_num (1=1) (2 3=0)

recode nelda30_num nelda31_num (3=0) (1 2=1)

recode nelda33_num (1 2=1)
 
recode nelda47_num (1 2=1) (3=0)

* Create index with theoretical range 0-16
egen nelda_index = rowtotal(nelda3_num nelda4_num nelda5_num nelda11_num nelda13_num nelda14_num nelda15_num nelda16_num nelda28_num nelda29_num nelda30_num nelda31_num nelda33_num nelda47_num nelda48_num nelda49_num)

fre nelda_index

gen nelda_index_nm = (nelda_index-10)/6
fre nelda_index_nm

corr nelda_index_nm ei_index_vdem


************************************************************************************************************************************

* 3 OVERVIEW OF INDIVIDUAL- AND CONTEXTUAL-LEVEL VARIABLES FOR ANALYSIS

* FINAL MODEL VARIABLES
fre fairelcc conspi_nm ///
	stfeco_nm polintr_nm inteff_nm lrscale_nm pid winner2 meduse_nm ///
	age_nm female eduyrs_nm mode ///
	gdppc_nm compvote ei_index_vdem nelda_index_nm
	
sum fairelcc conspi_nm ///
	stfeco_nm polintr_nm inteff_nm lrscale_nm pid winner2 meduse_nm ///
	age_nm female eduyrs_nm mode ///
	gdppc_nm compvote ei_index_vdem nelda_index_nm

* INDICATOR VARIABLE FOR CONSTANT N ACROSS MODELS (ONLY RESPONDENTS WITH VALID ANSWERS ON ALL MODEL COVARIATES)
egen validn = rowmiss(fairelcc conspi_nm ///
	distrst_nm stfeco_nm polintr_nm inteff_nm lrscale_nm pid winner2 meduse_nm ///
	age_nm female eduyrs_nm mode)
fre validn

* KEEP ONLY RESPONDENTS WITH VALID ANSWERS ON ALL MODEL COVARIATES
keep if validn==0
			
************************************************************************************************************************************

* 4 CREATE TABLE S2: DESCRIPTIVE STATISTICS
asdoc sum fairelcc conspi_nm ///
			stfeco_nm polintr_nm inteff_nm lrscale_nm pid winner2 meduse_nm ///
			age_nm female eduyrs_nm mode ///
			gdppc_nm compvote ei_index_vdem nelda_index_nm if validn==0, ///
		dec(2) save(tableS2.doc) replace


************************************************************************************************************************************

* 5 SAVE FINAL DATA SET FOR ANALYSIS INCLUDING ALL PRECODED VARIABLES
save "C:\Users\user\Desktop\REPLICATION FILES\data_analysis.dta", replace

************************************************************************************************************************************